/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

var scene;
var timer;
function main(canvas) {
    if (canvas.getContext) {

        scene = new Scene(canvas.getContext('2d'));
        initContent(scene, stage1);
    }
}
var wyniki = new Array();

function printScore(index, value, liTop)
{
    if ((!wyniki[index]) || (wyniki[index] < value))
    {
        liTop.childNodes[index].innerHTML = index + ": " + timeScore.getString(value);
        wyniki[index] = value;
    }
}
function StageStop(stage)
{
    scene.EventManager.flushInputs();
    var value = timeScore.getValue();
    var liTop =
            document.getElementById("top");
    if (stage == stage1)
    {
        window.clearInterval(timer);
        scene.clearScene();
        initContent(scene, stage2);
        printScore(0, value, liTop);

    }
    else
    {
        window.clearInterval(timer);
        scene.clearScene();
//        var li=document.createElement('li');    
//        li.innerHTML = "drugi";  
        printScore(1, value, liTop);
    }
}
var timeScore;
function initContent(scene, stage)
{
    timeScore = new TimeScore(scene,
            document.getElementById("time"),
            document.getElementById("top"));
    scene.addToScene(timeScore);
    var exit = new Exit(scene, stage);
    var maze = new Maze(scene, stage, exit);
    scene.addToScene(maze);
    scene.maze = maze;

    var sprite = new Sprite(scene);
    scene.EventManager.addKeyboardEvent(sprite);

    timer = window.setInterval(function() {
        scene.Draw();
    }, 50);

    scene.addToScene(new Gradient_Shadow(scene, sprite));

    scene.addToScene(new Items(scene));

    scene.addToScene(exit);
    scene.addToScene(sprite);



}

